# $Id: PKGBUILD 83707 2013-02-04 14:51:45Z seblu $
# Maintainer: Sébastien Luttringer <seblu@archlinux.org>
# Contributor: Paul Mattal <paul@archlinux.org>

pkgname=mailman
pkgver=2.1.15
pkgrel=3
pkgdesc='The GNU Mailing List Manager'
arch=(i686 x86_64)
license=('GPL')
url='http://www.list.org/'
depends=('glibc' 'python2' 'smtp-server')
# we need to have the mailman user to build mailman
makedepends=('mailman')
# 'Defaults.py' should not be changed by users; 'mm_cfg.py' should instead.
backup=('usr/lib/mailman/Mailman/mm_cfg.py')
install=$pkgname.install
source=("http://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tgz"
        'mailman-2.1-build.patch'
        "$pkgname.profile.sh"
        "$pkgname.profile.csh"
        "$pkgname.service")
md5sums=('7d207489e8e9de0727cb334d46029833'
         'ed04d062379eb21e39ce1e70e6b1ade2'
         'a9c71ec940c56173415fbd49087d10b0'
         '85a8c30ffc444e677b286f54df530482'
         'f3ea6ef02ab135274406ce52ea8bbb7b')

build() {
  cd $pkgname-$pkgver
  # some files in mailman doesn't use configure parameter
  find . -type f -exec \
    sed -i '1s,^#! \?/usr/bin/\(env \|\)python$,#!/usr/bin/python2,' {} \;
  # fix directory permissions to satisfy check_perms
  patch -p1 -i "$srcdir/mailman-2.1-build.patch"
  # set some sane defaults before the configure script has a chance to screw them up
  ./configure \
    --without-permcheck \
    --prefix=/usr/lib/mailman \
    --with-var-prefix=/var/lib/mailman \
    --with-mail-gid=mailman \
    --with-username=mailman \
    --with-groupname=mailman \
    --with-cgi-gid=http \
    --with-python=/usr/bin/python2 \
    --with-mailhost=localhost \
    --with-urlhost=localhost
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  # let's follow Fedora FHS way; Gentoo does it the other way round

  # Create a link so that the config file mm_cfg.py appears in config
  # directory /etc/mailman. We don't put mm_cfg.py in the config directory
  # because its executable code (python file) and the security policy wants
  # to keep executable code out of /etc and inside of a lib directory instead,
  # and because traditionally mm_cfg.py was in the Mailman subdirectory and
  # experienced mailman admins will expect to find it there. But having it
  # "appear" in the config directory is good practice and heading in the
  # right direction for FHS compliance.
  install -d -m755 "$pkgdir/etc/$pkgname"
  ln -sv /usr/lib/mailman/Mailman/mm_cfg.py "$pkgdir/etc/$pkgname/mm_cfg.py"
  # fix some permissions to satisfy check_perms
  chown -R mailman:mailman "$pkgdir"/{usr/lib/mailman,var/lib/mailman,etc/mailman/*}
  chown http:mailman "$pkgdir"/var/lib/mailman/archives/private
  chmod 2770 "$pkgdir"/var/lib/mailman/archives/private
  chmod 2755 "$pkgdir"/usr/lib/mailman/cgi-bin/*
  chmod 2755 "$pkgdir"/usr/lib/mailman/mail/mailman
  cd "$srcdir"
  # systemd
  install -Dm 644 $pkgname.service \
    "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  # profiles
  install -Dm 755 $pkgname.profile.sh "$pkgdir/etc/profile.d/$pkgname.sh"
  install -Dm 755 $pkgname.profile.csh "$pkgdir/etc/profile.d/$pkgname.csh"
}

# vim:set ts=2 sw=2 et:
